//
// A class to make it easy to tag exception propagation boundaries and
// get crash reports of exceptions that pass over same.

#include "exception_barrier.h"

enum {
	// Flag set by exception handling machinery when unwinding
	EH_UNWINDING = 0x00000002
};

ExceptionBarrier::ExceptionHandler ExceptionBarrier::s_handler_ = NULL;

// This function must be extern "C" to match up with the SAFESEH
// declaration in our corresponding ASM file
extern "C" EXCEPTION_DISPOSITION __cdecl
ExceptionBarrierHandler(struct _EXCEPTION_RECORD *exception_record, 
						void * establisher_frame, 
						struct _CONTEXT *context, 
						void * reserved)
{
	establisher_frame;  // unreferenced formal parameter
	reserved;
	if (!(exception_record->ExceptionFlags & EH_UNWINDING))
	{
		ExceptionBarrier::ExceptionHandler handler = ExceptionBarrier::handler();
		if (handler)
		{
			EXCEPTION_POINTERS ptrs = { exception_record, context };

			handler(&ptrs);
		}
	}
	return ExceptionContinueSearch;
}